<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('锜风公寓-房间列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            单元号：<select name="unit" th:with="type=${@dict.getType('qif_room_unit')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>莞e号：</label>
                            <input type="text" name="roomENum"/>
                        </li>
                        <li>
                            <label>房间号：</label>
                            <input type="text" name="roomNum"/>
                        </li>
                        <li>
                            房间类型：<select name="roomType" th:with="type=${@dict.getType('qif_room_type')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        <li>
                            房间状态：<select name="status" th:with="type=${@dict.getType('qif_room_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>入住时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="resetRoomPre()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="qif:room:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="qif:room:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="qif:room:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="qif:room:import">
                <i class="fa fa-download"></i> 导入
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('qif:room:edit')}]];
    var listFlag = [[${@permission.hasPermi('qif:guest:list')}]];
    var removeFlag = [[${@permission.hasPermi('qif:room:remove')}]];
    var prefix = ctx + "qif/room";
    var types = [[${@dict.getType('qif_room_unit')}]];
    var roomStatus = [[${@dict.getType('qif_room_status')}]];
    var roomTypes = [[${@dict.getType('qif_room_type')}]];
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            sortOrder: "desc",
            modalName: "锜风公寓-房间",
            columns: [{
                checkbox: true
            },
                {
                    field: 'roomId',
                    title: '房间id',
                    visible: false
                },
                {
                    field: 'unit',
                    title: '单元号',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(types, value);
                    }
                },
                {
                    field: 'roomNum',
                    title: '房间号'
                },
                {
                    field: 'rent',
                    title: '租金(元)',
                    // 添加格式化函数，在数值前加上人民币符号
                    formatter: function(value, row, index) {
                        // 确保值是数字类型，如果为空则显示0
                        return '¥' + (parseFloat(value) || 0);
                    }
                },
                {
                    field: 'deposit',
                    title: '押金(元)',
                    // 添加格式化函数，在数值前加上人民币符号
                    formatter: function(value, row, index) {
                        // 确保值是数字类型，如果为空则显示0
                        return '¥' + (parseFloat(value) || 0);
                    }
                },
                {
                    field: 'keyCard',
                    title: '房卡(元)',
                    // 添加格式化函数，在数值前加上人民币符号
                    formatter: function(value, row, index) {
                        // 确保值是数字类型，如果为空则显示0
                        return '¥' + (parseFloat(value) || 0);
                    }
                },
                {
                    field: 'water',
                    title: '水表(方)'
                },
                {
                    field: 'electricity',
                    title: '电表(度)'
                },
                {
                    field: 'sanitationFee',
                    title: '卫生费(元)',
                    // 添加格式化函数，在数值前加上人民币符号
                    formatter: function(value, row, index) {
                        // 确保值是数字类型，如果为空则显示0
                        return '¥' + (parseFloat(value) || 0);
                    }
                },
                {
                    field: 'checkInTime',
                    title: '入住时间'
                },
                {
                    field: 'expirationTime',
                    title: '到期时间'
                },
                {
                    field: 'roomType',
                    title: '房间类型',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(roomTypes, value);
                    }
                },
                {
                    field: 'status',
                    title: '房间状态',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(roomStatus, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.roomId + '\')"><i class="fa fa-list-ul"></i>入住人员</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.roomId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.roomId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 重置搜索表单 */
    function resetRoomPre() {
        // 1. 重置下拉选择框为默认空值
        $("select[name='unit']").val("");
        $("select[name='roomType']").val("");
        $("select[name='status']").val("");

        // 2. 清空文本输入框
        $("input[name='roomENum']").val("");
        $("input[name='roomNum']").val("");

        // 3. 清空时间输入框
        resetDate();

        // 4. 重置表格搜索状态（可选，确保表格刷新为全量数据）
        $.table.search();
    }
    /*房客列表-详细*/
    function detail(roomId) {
        var url = prefix + '/detail/' + roomId;
        $.modal.openTab("房客列表", url);
    }


    /* 房间状态-0:在租 */
    function enable(roomId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"roomId": roomId, "status": 0});
        })
    }

    /* 房间状态-1:逾期 */
    function disable(roomId) {
        $.modal.confirm("确认要停用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"roomId": roomId, "status": 1});
        })
    }

    /* 房间状态-2:维修 */
    function enable(roomId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"roomId": roomId, "status": 2});
        })
    }

    /* 房间状态-3:空房 */
    function enable(roomId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"roomId": roomId, "status": 3});
        })
    }

    /* 房间状态-4:续住 */
    function enable(roomId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"roomId": roomId, "status": 4});
        })
    }

    /* 房间状态-5:新租 */
    function enable(roomId) {
        $.modal.confirm("确认要启用用户吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"roomId": roomId, "status": 5});
        })
    }


</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果房间已经存在，更新这条数据。"> 是否更新已经存在的房间数据
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>